import time

import allure
from selenium.webdriver.common.by import By

from bazhuayun.page.base_octopus_cloud import BaseOctopusCloud
from bazhuayun.utils.log_utils import logger


class ChannelPage(BaseOctopusCloud):
    _CHANNEL_NAME = By.XPATH, '//*[@class="el-input__inner"]'
    _CHANNEL_HEAD = By.XPATH, '(//*[@class="el-select__input"])[2]'
    _CHANNEL_HEAD_CHOOSE = By.XPATH, '(//*[text()="【机器人，咨询请入群】赫敏-霍格沃兹测试开发"])[4]'
    _CHANNEL_GROUP = By.XPATH, '(//*[@class="el-input__inner"])[7]'
    _CHANNEL_GROUP_CHOOSE = By.XPATH, '//*[text()="测吧"]'
    _CHANNEL_MODE_NAME = By.XPATH, '(//*[@class="el-input__inner"])[8]'
    _CHANNEL_MODE_NAME_CHOOSE = By.XPATH, '//*[text()="qqqqq"]'
    _CHANNEL_MODE = By.XPATH, '(//*[@class="el-select__input"])[3]'
    _CHANNEL_MODE_CHOOSE = By.XPATH, '(//*[@class="inline-block ml1"])[1]'
    _CHANNEL_SUBMIT = By.XPATH, '//*[text()="提交"]'
    _CHANNEL_WOYIZHIXIAO = By.CSS_SELECTOR, ".el-button.el-button--default.el-button--small.el-button--primary "

    @allure.step("完成添加渠道操作")
    def channel(self, name):
        # 名称
        time.sleep(2)
        self.find_ele(*self._CHANNEL_NAME).click()
        self.find_ele(*self._CHANNEL_NAME).send_keys(name)
        # 渠道负责人
        time.sleep(2)
        self.find_ele(*self._CHANNEL_HEAD).click()
        time.sleep(2)
        self.find_ele(*self._CHANNEL_HEAD_CHOOSE).click()
        time.sleep(2)
        # 群名称
        self.find_ele(*self._CHANNEL_GROUP).click()
        time.sleep(2)
        self.find_ele(*self._CHANNEL_GROUP_CHOOSE).click()
        # 返单模板
        time.sleep(2)
        self.find_ele(*self._CHANNEL_MODE_NAME).click()
        self.find_ele(*self._CHANNEL_MODE_NAME_CHOOSE).click()
        # 返单通知微信号
        self.find_ele(*self._CHANNEL_MODE).click()
        time.sleep(2)
        self.find_ele(*self._CHANNEL_MODE_CHOOSE).click()
        # 提交
        self.find_ele(*self._CHANNEL_SUBMIT).click()
        # 点击我已知晓
        self.find_ele(*self._CHANNEL_WOYIZHIXIAO).click()
        logger.info("完成添加渠道操作")
        from bazhuayun.page.channel_add_page import ChannelAddPage
        return ChannelAddPage(self.driver)







